<template>
	<view>
		<custom-navi :show-home="false">消息和铃声设置</custom-navi>
		<view class="inform">
			<view class="inform-push">
				<view>
					开启消息推送
				</view>
				<view class="status">{{status}}</view>
			</view>
			<view class="inform-open">
				<view class="text">
					开启后，会受到消息的横幅通知推送，请务必保持开启，以免消息推送延迟。
				</view>
				<view class="openBtn" @click="unfold">
					{{btnStatus}}
				</view>
			</view>
			<view class="inform-shake">
				<view>
					震动提醒
				</view>
				<view class="shakeBtn">
					<mrhardSwitch :checked="vibrateStatus" bgColorActive="rgba(12, 212, 211, 1)" bgColorDefault="rgba(217, 217, 217, 1)" textColor="@bfffc2" width="80rpx"
					 height="42rpx" buttonSize='38rpx' textSize="36rpx" @change="changeSwitch"></mrhardSwitch>
				</view>
			</view>
			<view class="inform-bell">
				<view class="inform-bell-title">
					铃声
				</view>
				<!-- <view class="inform-bell-name">经典女声版</view> -->
				<view class="inform-bell-icon" @click="chooseBell">
					<image src="/static/little-more.png" mode=""></image>
				</view>
				<view class="inform-bell-name" @click="chooseBell">{{bell}}</view>
			</view>
			<view class="inform-explain">
				<view class="inform-explain-txt">
					物联云商商家端运行时有新预定消息时，当前手机会收到铃声提醒。
				</view>
			</view>
			<view class="inform-num">
				<view>
					铃声播报次数
				</view>
				<view class="status" @click="referral">使用推荐设置</view>
			</view>
			<view class="inform-undetermined">
				<view class="inform-undetermined-remind">
					预订单提醒
				</view>
				<view class="inform-undetermined-list">
					<view class="title">
						预订单等待确认
					</view>
					<view class="icon" @click="choice">
						<image src="../../../../../static/little-more.png" mode=""></image>
					</view>
					<view class="recommend" @click="choice">
						{{preOrderAwaitConfirm}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import mrhardSwitch from "../../../components/mrhard-switch/mrhard-switch.vue";
	import settings from "../../../../settings.js";
	console.log(settings);
	console.log("是否开启消息推送:"+settings.notificationEnabled);
	export default {
		components: {
			mrhardSwitch
		},
		data() {
			return {
				status: settings.notificationEnabled?"已开启":"未开启",
				btnStatus: settings.notificationEnabled?"关闭":"开启",
				vibrateStatus: settings.vibrateStatus,
				bell: settings.bellMap.get(settings.bell),
				preOrderAwaitConfirm: settings.remindMap.get(settings.preOrderAwaitConfirm)
			}
		},
		onShow() {
			let oldStatus=settings.notificationEnabled;
			let newStatus=settings.checkNotificationPermit();
			if(oldStatus!=newStatus){
				settings.setNotificationEnabled(newStatus);
				console.log(settings)
				this.status=settings.notificationEnabled?"已开启":"未开启";
				this.btnStatus=settings.notificationEnabled?"关闭":"开启";
			}
			this.bell=settings.bellMap.get(settings.bell);
			this.preOrderAwaitConfirm=settings.remindMap.get(settings.preOrderAwaitConfirm);
		},
		methods: {
			unfold(){ // 开启按钮
				//#ifdef APP-PLUS
				if(settings.sys){
					var UIApplication = plus.ios.import("UIApplication");  
					var NSURL = plus.ios.import("NSURL");  
					var setting = NSURL.URLWithString("app-settings:");  
					var application = UIApplication.sharedApplication();  
					application.openURL(setting);  
					plus.ios.deleteObject(setting);  
					plus.ios.deleteObject(application);  
				}else{
					var main=plus.android.runtimeMainActivity();
					var Intent = plus.android.importClass('android.content.Intent');  
					var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
					intent.putExtra('android.provider.extra.APP_PACKAGE', main.getPackageName());  
					main.startActivity(intent);
				}
				//#endif
			},
			changeSwitch(e) { //切换震动提醒
				settings.setVibrateStatus(e);
			},
			chooseBell(){ // 选择铃声
				uni.navigateTo({
					url: "bellSet/index"
				})
			},
			referral(){ // 使用推荐设置
				settings.setPreOrderAwaitConfirm(3);
				this.preOrderAwaitConfirm=settings.remindMap.get(settings.preOrderAwaitConfirm);
			},
			choice(){ // 预订单等待确认
				uni.navigateTo({
					url: "remindSet/index"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.inform {
		&-push {
			margin-top: 30rpx;
			height: 114rpx;
			background: rgba(255, 255, 255, 1);
			opacity: 1;
			line-height: 114rpx;
			padding: 0 32rpx;

			view {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: rgba(80, 80, 80, 1);
				opacity: 1;
				display: inline-block;
			}

			.status {
				float: right;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: rgba(153, 153, 153, 1);
				opacity: 1;
			}

		}

		&-open {
			height: 120rpx;
			display: flex;
			align-items: center;
			padding: 0 32rpx;
			.text {
				width: 600rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: rgba(153, 153, 153, 1);
				opacity: 1;
			}

			.openBtn {
				width: 80rpx;
				height: 44rpx;
				background: rgba(255, 255, 255, 1);
				border: 1rpx solid rgba(153, 153, 153, 1);
				opacity: 1;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 40rpx;
				color: rgba(80, 80, 80, 1);
				opacity: 1;
				text-align: center;
				margin-left: 10rpx;
			}
		}

		&-shake {
			margin-top: 30rpx;
			height: 114rpx;
			background: rgba(255, 255, 255, 1);
			opacity: 1;
			line-height: 114rpx;
			padding: 0 32rpx;
			border-bottom: 1rpx solid rgba(217, 217, 217, 1);

			view {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: rgba(80, 80, 80, 1);
				opacity: 1;
				display: inline-block;
			}

			.shakeBtn {
				float: right;
				margin-top: 30rpx;
			}
		}

		&-bell {
			margin-top: 30rpx;
			height: 114rpx;
			background: rgba(255, 255, 255, 1);
			opacity: 1;
			line-height: 114rpx;
			padding: 0 32rpx;
			view{
				display: inline-block;
				
			}
			&-title{
				font-size:28rpx;
				font-family:PingFang SC;
				font-weight:400;
				color:rgba(80,80,80,1);
				opacity:1;
			}
			&-name{
				float: right;
				font-size:28rpx;
				font-family:PingFang SC;
				font-weight:400;
				color:rgba(153,153,153,1);
				opacity:1;
			}
			&-icon{
				float: right;
				margin-left: 40rpx;
				
				opacity:1;
				image{
					width:16rpx;
					height:22rpx;
					margin-top: 48rpx;
				}
			}
		}
		&-explain{
			width:756rpx;
			height: 120rpx;
			display: flex;
			align-items: center;
			padding: 0 32rpx;
			&-txt{
				width:756rpx;
				font-size:28rpx;
				font-family:PingFang SC;
				font-weight:400;
				color:rgba(153,153,153,1);
				opacity:1;
			}
		}
		&-num{
			height: 114rpx;
			background: rgba(255, 255, 255, 1);
			opacity: 1;
			line-height: 114rpx;
			padding: 0 32rpx;
			border-bottom: 1rpx solid rgba(217, 217, 217, 1);
			view {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: rgba(80, 80, 80, 1);
				opacity: 1;
				display: inline-block;
			}
			
			.status {
				float: right;
				font-size:28rpx;
				font-family:PingFang SC;
				font-weight:400;
				color:rgba(12,212,211,1);
				opacity:1;
			}
		}
		&-undetermined{
			padding: 30rpx;
			background:rgba(255,255,255,1);
			opacity:1;
			&-remind{
				width:200rpx;
				height:26rpx;
				font-size:24rpx;
				font-family:PingFang SC;
				font-weight:400;
				line-height:26rpx;
				color:rgba(179,179,179,1);
				opacity:1;
				padding: 0 10rpx;
				border-left: 4rpx solid rgba(179,179,179,1);
			}
			&-list{
				margin-top: 30rpx;
				height: 48rpx;
				background: rgba(255, 255, 255, 1);
				opacity: 1;
				line-height: 48rpx;
				view{
					display: inline-block;
				}
				.recommend{
					float: right;
					font-size:28rpx;
					font-family:PingFang SC;
					font-weight:400;
					color:rgba(153,153,153,1);
					opacity:1;
				}
				.title{
					font-size:28rpx;
					font-family:PingFang SC;
					font-weight:400;
					color:rgba(80,80,80,1);
					opacity:1;
				}
				.icon{
					float: right;
					margin-left: 40rpx;
					opacity:1;
					image{
						width:16rpx;
						height:22rpx;
						margin-top: 15rpx;
					}
				}
			}
		}
	}
</style>